<template>
        <div class="nav-part" ref="nav">
            <div class="nav-top">
                <div class="title"><slot name="titleText"></slot></div>
                <div class="link"><router-link to="/Find">查看更多<i class="iconfont icon-jiantou"></i></router-link></div>
            </div>
            <div class="list-part" @touchstart = touchIn @touchmove = touchOn>
                <ul class="nav-ul" :style="{'transform'  : `translateX(-${touchMove}px)`,'width' : `${8*songListData.length+6}rem`}" ref="companyStyle">
                    <li class="nav-li" v-for="item in songListData" :key="item.id" ref="myLi">
                        <router-link to="/Find">
                        <div class="list">
                            <img :src="item.picUrl" alt="" class="list-img">
                            <p class="sum"><i class="iconfont icon-24gf-playSquare"></i><span>{{item.playCount}}</span></p>
                            <i class="play iconfont icon-24gf-playCircle"></i>
                        </div>
                        <p class="title">{{item.name}}</p>
                        </router-link>
                    </li>
                    <li class="jmp">
                        <div><i class=" iconfont icon-icon_220" ></i>左滑更多</div>
                    </li>
                </ul>
            </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            ulWidth : "",
            ulLeft : "",
            touchFirst : 0,
            touchMove : 0,
            windowWidth : 0
        }
    },
    props:{
        songListData:{
            type : Array
        }
    },
    methods:{
        touchIn(e){
            this.touchFirst = e.changedTouches[0].pageX+this.touchMove;
        },
        touchOn(e){
                this.touchMove = this.touchFirst-e.changedTouches[0].pageX;
                let maxWidth = 128*this.songListData.length+48-this.windowWidth;
                if(this.touchMove<0){
                    this.touchMove = 0;
                    return;
                }else if(this.touchMove>maxWidth){
                    this.touchMove = maxWidth;
                    return;
                }
        }
    },
    mounted(){
        this.$nextTick(()=>{
                setTimeout(()=>{
                    this.windowWidth = this.$refs.nav.offsetWidth
                    this.ulList = this.$refs.companyStyle.offsetWidth
                },200)
        })
    }
}
</script>

<style lang="scss" scoped>
    .nav-part {
        width: 90%;
        margin: auto;
        padding: 1rem 0rem;
    }

    .nav-top {
        width: 100%;
        height: 1.5rem;
        margin: 0.5rem 0rem ;
        display: flex;
        justify-content: space-between;

        .title {
            text-align: left;
            font-size: 1.2rem;
            font-weight: bold;
        }

        .link {
            padding:0rem 0.3rem;
            line-height: 1.4rem;
            font-size: 0.6rem;
            border: 1px solid #ccc;
            border-radius: 5rem;

            >a {
                color: #000;
                text-decoration: none;
                font-size: 0.8rem;
            }

            .iconfont {
                font-size: 0.8rem;
            }
        }
    }
    .list-part {
        width: 100%;
        overflow: hidden;
    }

    .nav-ul {
        display: flex;
    }

    .nav-li {
        width: 8rem;
        height: 9rem;
        >a {
            color: #000;
            text-decoration: none;
        }
        
        .title {
            width: 100%;
            height: 1.6rem;
            padding: 0rem 0.2rem;
            box-sizing: border-box;
            font-size: 0.8rem;
            overflow: hidden;
            overflow:hidden; 
            text-overflow:ellipsis;
            display:-webkit-box; 
            -webkit-box-orient:vertical;
            -webkit-line-clamp:2; 
            margin-top: 0.4rem;
        }

        .list {
            margin: auto;
            flex-basis: 7rem;
            width: 7rem;
            height: 7rem;
            border-radius: 0.5rem;
            position: relative;
            overflow: hidden;

            .play {
                position: absolute;
                bottom: 0.2rem;
                right: 0.2rem;
                color: #fff;
            }

            .sum {
                position: absolute;
                font-size: 0.85rem;
                top: 0.2rem;
                right: 0.2rem;
                color: #fff;
            }

            >img {
                width: 100%;
            }
        }
        }
        .jmp {
            position: relative;
            width: 3rem;
            height: 9rem;
            flex-basis: 3rem;
            border-radius: 0.5rem;
            background-color: rgb(134, 134, 134);

            >div {
                width: 1rem;
                position: absolute;
                top: 50%;
                left: 50%;
                color: rgb(255, 255, 255);
                transform: translate(-50%,-50%);
            }
        }
</style>